package 第四章类与对象.员工类;

import java.time.LocalDate;
import java.util.Objects;

public class Employee {
    private String name;
    private double salary;
    private LocalDate hireDay;

    public Employee() {
    }

    public Employee(String name, double salary, LocalDate hireDay) {
        this.name = name;
        this.salary = salary;
        this.hireDay = hireDay;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getSalary() {
        return salary;
    }

    public void setSalary(double salary) {
        this.salary = salary;
    }

    public LocalDate getHireDay() {
        return hireDay;
    }

    public void setHireDay(LocalDate hireDay) {
        this.hireDay = hireDay;
    }

    public void raiseSalary(double byPercent){
        double raise = salary * byPercent / 100;
        salary += raise;
    }

    //重写object的方法
    @Override
    public boolean equals(Object obj) {
        //地址值相同时直接判断为相同；
        if(this == obj) {
            return true;
        }

        //如果其中被比较的这个应用指向的是null，则判断为不同；
        if (obj == null){
            return false;
        }

        //如果两个引用的类型不相同，则判断为不同；
        if (getClass() != obj.getClass()){
            return false;
        }

        //两个类相同，将另外的类强转为Employee；
        Employee other = (Employee) obj;

        //剩下的情况中，比较两个类的关键字；
        //运用Objects工具类中的equals方法，这样可以避免name和hireDay的字段为空的方法；
        return Objects.equals(this.name,other.name)
                && salary == other.salary
                && Objects.equals(hireDay, other.hireDay);

    }
}
